<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 스타 운세 데이터 생성 컨트롤러
 * 연예인의 사주정보를 토대로 운세 결과 키값(db_express)을 생성해 DB에 저장한다.
 */
class Starunse extends CI_Controller {
	
	var $data = array();
	
	function __construct() {
		parent::__construct();
		$this->data['sess_userinfo'] = $this->session->userdata('userinfo');

		$this->load->model('star/Starunse_model', 'model');
		$this->load->helper(array('pagenavi'));
	}
	
	// Default
	function index() {
		$this->star_list();
	}
	
	/**
	 * 게시물 리스트
	 */
	function star_list() {
		log_message('debug', "@@@@ Starunse::star_list()");
		
		$keyword = $this->input->get('keyword', TRUE);
		$page    = $this->input->get('page', TRUE);
		$order   = $this->input->get('order', TRUE);
		$sort    = $this->input->get('sort', TRUE);

		$current_page = empty($page) ? 1 : $page;

		$page_size  = LIST_PAGE_SIZE;	// 한 페이지에 보여줄 글 수
		$block_size = LIST_BLOCK_SIZE;	// 네비영역의 한 블록에 보여줄 페이지 수

		$total_cnt  = $this->model->get_artist_total_count($keyword);	// 총 글 수

		$this->data['artist_list'] = $this->model->select_artist_list($keyword, $current_page, $page_size, $order, $sort);
		
		$this->data['navi'] = page_navigation($current_page, $total_cnt, $page_size, $block_size, $this->uri->uri_string());
		
		$this->data['order'] = $order;
		$this->data['sort']  = $sort;
		
		$this->load->view('star/artist_list_v.php', $this->data);
	}
	
	/**
	 * 스타 상세 정보
	 */
	function artist_detail() {
		log_message('debug', "@@@@ Starunse::artist_detail()");
		
		$idx = $this->input->get('idx', TRUE);
		$this->data['artist'] = $this->model->get_artist($idx);
		
		$this->load->view('star/artist_detail_pop_v.php', $this->data);
	}

	/**
	 * 정보 수정
	 */
	function modify() {
		log_message('debug', "@@@@ Starunse::modify()");
		
		$artist = $this->input->post();
		$this->model->update_artist($artist);
		
		echo "<script type='text/javascript'>alert('수정완료');opener.location.reload();window.close();</script>";
	}

	/**
	 * 등록
	 */
	function register_form() {
		log_message('debug', "@@@@ Starunse::register_form()");
		
		$artist['idx'] = '';
	    $artist['artist_name'] = '';
	    $artist['job'] = '';
	    $artist['birthday'] = '';
	    $artist['achievement'] = '';
	    $artist['family'] = '';
	    $artist['agency'] = '';
	    $artist['debut'] = '';
	    $artist['award'] = ''; 
	    $artist['photo'] = '';
	    $artist['body'] = '';
	    $artist['web_site_type'] = '';
	    $artist['web_site_url'] = '';
	    $artist['career'] = ''; 
	    $artist['sex'] = '';
	    $artist['birth_yyyy'] = '';
	    $artist['birth_mm'] = '';
	    $artist['birth_dd'] = '';
	    $artist['keyword'] = '';
		
		$this->data['artist'] = $artist;
		
		$this->load->view('star/artist_detail_pop_v.php', $this->data);
	}
	
	/**
	 * 등록
	 */
	function register() {
		log_message('debug', "@@@@ Starunse::register()");
		
		$artist = $this->input->post();
		unset($artist['idx']);
		$this->model->insert_artist($artist);
		
		echo "<script type='text/javascript'>alert('등록완료');opener.location.reload();window.close();</script>";
	}
	
	function remove_ok() {
		$idx  = $this->input->post('idx');
		$page = $this->input->post('page');
		$this->model->delete_artist($idx);
		echo "<script type='text/javascript'>alert('삭제완료');history.back();</script>";
	}
	
	/*****************************************************************************************
	 * db_express값 생성해서 저장
	 *----------------------------------------------------------------------------------------
	 * 
	 * 
	 * 1. 
	 * 2. 
	 * 3. 
	 * 4. 
	 * 5. 
	 *****************************************************************************************/
	function db_express() {
		log_message('debug', "@@@@ Starunse::db_express()");
		

		$artist_list = $this->model->select_artist_all_list();
		

		//------------------------------------------------------------------
		// 파라미터값 셋팅
		//------------------------------------------------------------------

		// 기본값으로 셋팅 (의미있는 값이라기 보단 그냥 보내는 값이다.)
		$userinfo['your_month']     = '';
		$userinfo['your_hour']      = '';
		$userinfo['your_year']      = '';
		$userinfo['your_solunar']   = '';
		$userinfo['your_user_name'] = '';
		$userinfo['your_day']       = '';
		$userinfo['your_youn']      = '';
		$userinfo['your_min']       = '';
		$userinfo['request_min']    = '00';
		$userinfo['cate']           = 'saju';
		$userinfo['sel']            = '1';
		$userinfo['solution_var']   = 'DB';
		$userinfo['url']            = '';
		$userinfo['radio_10']       = '';
		$userinfo['radio_14']       = '';
		$userinfo['intstick2z']     = '';
		$userinfo['radio_13']       = '';
		$userinfo['radio_12']       = '';
		$userinfo['intstick3zz']    = '';
		$userinfo['radio_11']       = '';
		$userinfo['intstick1']      = '2';
		$userinfo['intstick2zz']    = '';
		$userinfo['radio_18']       = '';
		$userinfo['intstick2']      = '1';
		$userinfo['radio_17']       = '';
		$userinfo['intstick3']      = '0';
		$userinfo['radio_16']       = '';
		$userinfo['intstick4']      = '0';
		$userinfo['radio_15']       = '';
		$userinfo['intstick5']      = '0';
		$userinfo['intstick6']      = '1';
		$userinfo['radio_19']       = '';
		$userinfo['cyear']          = '';
		$userinfo['MtMonth']        = '';
		$userinfo['num_1']          = '';
		$userinfo['num_2']          = '';
		$userinfo['intstick1zz']    = '';
		$userinfo['dream_type']     = '';
		$userinfo['intstick3z']     = '';
		$userinfo['hangul_1']       = '';
		$userinfo['blood']          = '';
		$userinfo['hangul_5']       = '';
		$userinfo['hangul_4']       = '';
		$userinfo['hangul_3']       = '';
		$userinfo['sasangw']        = '';
		$userinfo['hangul_2']       = '';
		$userinfo['jumsa']          = '';
		$userinfo['ysung']          = '';
		$userinfo['tele']           = '';
		$userinfo['name_5']         = '';
		$userinfo['name_4']         = '';
		$userinfo['search_month']   = '';
		$userinfo['jumin2']         = '';
		$userinfo['jumin1']         = '';
		$userinfo['name12_1']       = '';
		$userinfo['MtYear']         = '';
		$userinfo['sasangm']        = '';
		$userinfo['selectday']      = '';
		$userinfo['showInputNN2']   = '';
		$userinfo['showInputNN3']   = '';
		$userinfo['intstick1z']     = '';
		$userinfo['d']              = '';
		$userinfo['intstick4zz']    = '';
		$userinfo['b']              = '';
		$userinfo['c']              = '';
		$userinfo['a']              = '';
		$userinfo['intstick5zz']    = '';
		$userinfo['what']           = '';
		$userinfo['bloodm']         = '';
		$userinfo['bloodw']         = '';
		$userinfo['intstick6zz']    = '';
		$userinfo['intstick6z']     = '';
		$userinfo['search_year']    = '';
		$userinfo['radio_51']       = '';
		$userinfo['radio_52']       = '';
		$userinfo['radio_53']       = '';
		$userinfo['radio_50']       = '';
		$userinfo['ref_var']        = '';
		$userinfo['radio_48']       = '';
		$userinfo['radio_49']       = '';
		$userinfo['name_3']         = '';
		$userinfo['name_2']         = '';
		$userinfo['name_1']         = '';
		$userinfo['radio_42']       = '';
		$userinfo['radio_43']       = '';
		$userinfo['radio_40']       = '';
		$userinfo['radio_41']       = '';
		$userinfo['radio_46']       = '';
		$userinfo['radio_47']       = '';
		$userinfo['radio_44']       = '';
		$userinfo['msung']          = '';
		$userinfo['radio_45']       = '';
		$userinfo['intstick4z']     = '';
		$userinfo['showInputFN2']   = '';
		$userinfo['rd']             = '';
		$userinfo['radio_37']       = '';
		$userinfo['cday']           = '';
		$userinfo['radio_38']       = '';
		$userinfo['radio_39']       = '';
		$userinfo['name']           = '';
		$userinfo['radio_33']       = '';
		$userinfo['radio_34']       = '';
		$userinfo['radio_35']       = '';
		$userinfo['radio_36']       = '';
		$userinfo['radio_30']       = '';
		$userinfo['radio_31']       = '';
		$userinfo['radio_32']       = '';
		$userinfo['radio_2']        = '';
		$userinfo['intstick5z']     = '';
		$userinfo['dsearch']        = '';
		$userinfo['radio_3']        = '';
		$userinfo['radio_1']        = '';
		$userinfo['dream_name']     = '';
		$userinfo['MtDay']          = '';
		$userinfo['radio_28']       = '';
		$userinfo['radio_29']       = '';
		$userinfo['radio_26']       = '';
		$userinfo['radio_27']       = '';
		$userinfo['radio_24']       = '';
		$userinfo['radio_7']        = '';
		$userinfo['radio_25']       = '';
		$userinfo['radio_6']        = '';
		$userinfo['radio_22']       = '';
		$userinfo['radio_5']        = '';
		$userinfo['radio_23']       = '';
		$userinfo['radio_4']        = '';
		$userinfo['cmonth']         = '';
		$userinfo['radio_20']       = '';
		$userinfo['name1']          = '';
		$userinfo['radio_21']       = '';
		$userinfo['serial']         = '';
		$userinfo['radio_9']        = '';
		$userinfo['radio_8']        = '';
		
		// 나의 사주 정보 셋팅
		// $userinfo['yyyy']           = $this->input->post('target_yyyy');
		// $userinfo['user_id']        = $this->input->post('user_id');
		// $userinfo['user_name']      = $this->input->post('user_name');
		// $userinfo['sex']            = $this->input->post('sex');
		// $userinfo['solunar']        = $this->input->post('birth_solunar');
		// $userinfo['my_solnuar']     = $userinfo['solunar'];
		// $userinfo['request_year']   = $this->input->post('birth_yyyy');
		// $userinfo['request_month']  = $this->input->post('birth_mm');
		// $userinfo['request_day']    = $this->input->post('birth_dd');
		// $userinfo['request_hour']   = $this->input->post('birth_hh');
		
		$userinfo['yyyy']           = date('Y',time());
		$userinfo['solunar']        = 'solar';
		$userinfo['my_solnuar']     = $userinfo['solunar'];
		$userinfo['request_hour']   = '0';
		$userinfo['youn']           = '0';
		$userinfo['setDate']        = date("Y-m-d",time());	// 오늘날짜

		foreach ($artist_list as $artist) {
			$userinfo['user_name']      = $artist['artist_name'];
			$userinfo['sex']            = $artist['sex'];
			$userinfo['request_year']   = $artist['birth_yyyy'];
			$userinfo['request_month']  = $artist['birth_mm'];
			$userinfo['request_day']    = $artist['birth_dd'];

			// 운세 결과 키값(db_express) 데이터 가져오기
			$star_unse = $this->model->get_db_express($userinfo);

			// DB에 db_express값 저장
			foreach ($star_unse as $item) {
				$this->model->insert_artist_express($artist['idx'], $item['table_name'], $item['db_express']);
			}
		}



		// 뷰로 이동
//		$this->load->view('star/starunse_v.php', $this->data);
	}

	function test() {
		log_message('debug', "@@@@ Starunse::test()");
		

		$artist_list = $this->model->select_artist_list();
		

		//------------------------------------------------------------------
		// 파라미터값 셋팅
		//------------------------------------------------------------------

		// 기본값으로 셋팅 (의미있는 값이라기 보단 그냥 보내는 값이다.)
		$userinfo['your_month']     = '';
		$userinfo['your_hour']      = '';
		$userinfo['your_year']      = '';
		$userinfo['your_solunar']   = '';
		$userinfo['your_user_name'] = '';
		$userinfo['your_day']       = '';
		$userinfo['your_youn']      = '';
		$userinfo['your_min']       = '';
		$userinfo['request_min']    = '00';
		$userinfo['cate']           = 'saju';
		$userinfo['sel']            = '1';
		$userinfo['solution_var']   = 'DB';
		$userinfo['url']            = '';
		$userinfo['radio_10']       = '';
		$userinfo['radio_14']       = '';
		$userinfo['intstick2z']     = '';
		$userinfo['radio_13']       = '';
		$userinfo['radio_12']       = '';
		$userinfo['intstick3zz']    = '';
		$userinfo['radio_11']       = '';
		$userinfo['intstick1']      = '2';
		$userinfo['intstick2zz']    = '';
		$userinfo['radio_18']       = '';
		$userinfo['intstick2']      = '1';
		$userinfo['radio_17']       = '';
		$userinfo['intstick3']      = '0';
		$userinfo['radio_16']       = '';
		$userinfo['intstick4']      = '0';
		$userinfo['radio_15']       = '';
		$userinfo['intstick5']      = '0';
		$userinfo['intstick6']      = '1';
		$userinfo['radio_19']       = '';
		$userinfo['cyear']          = '';
		$userinfo['MtMonth']        = '';
		$userinfo['num_1']          = '';
		$userinfo['num_2']          = '';
		$userinfo['intstick1zz']    = '';
		$userinfo['dream_type']     = '';
		$userinfo['intstick3z']     = '';
		$userinfo['hangul_1']       = '';
		$userinfo['blood']          = '';
		$userinfo['hangul_5']       = '';
		$userinfo['hangul_4']       = '';
		$userinfo['hangul_3']       = '';
		$userinfo['sasangw']        = '';
		$userinfo['hangul_2']       = '';
		$userinfo['jumsa']          = '';
		$userinfo['ysung']          = '';
		$userinfo['tele']           = '';
		$userinfo['name_5']         = '';
		$userinfo['name_4']         = '';
		$userinfo['search_month']   = '';
		$userinfo['jumin2']         = '';
		$userinfo['jumin1']         = '';
		$userinfo['name12_1']       = '';
		$userinfo['MtYear']         = '';
		$userinfo['sasangm']        = '';
		$userinfo['selectday']      = '';
		$userinfo['showInputNN2']   = '';
		$userinfo['showInputNN3']   = '';
		$userinfo['intstick1z']     = '';
		$userinfo['d']              = '';
		$userinfo['intstick4zz']    = '';
		$userinfo['b']              = '';
		$userinfo['c']              = '';
		$userinfo['a']              = '';
		$userinfo['intstick5zz']    = '';
		$userinfo['what']           = '';
		$userinfo['bloodm']         = '';
		$userinfo['bloodw']         = '';
		$userinfo['intstick6zz']    = '';
		$userinfo['intstick6z']     = '';
		$userinfo['search_year']    = '';
		$userinfo['radio_51']       = '';
		$userinfo['radio_52']       = '';
		$userinfo['radio_53']       = '';
		$userinfo['radio_50']       = '';
		$userinfo['ref_var']        = '';
		$userinfo['radio_48']       = '';
		$userinfo['radio_49']       = '';
		$userinfo['name_3']         = '';
		$userinfo['name_2']         = '';
		$userinfo['name_1']         = '';
		$userinfo['radio_42']       = '';
		$userinfo['radio_43']       = '';
		$userinfo['radio_40']       = '';
		$userinfo['radio_41']       = '';
		$userinfo['radio_46']       = '';
		$userinfo['radio_47']       = '';
		$userinfo['radio_44']       = '';
		$userinfo['msung']          = '';
		$userinfo['radio_45']       = '';
		$userinfo['intstick4z']     = '';
		$userinfo['showInputFN2']   = '';
		$userinfo['rd']             = '';
		$userinfo['radio_37']       = '';
		$userinfo['cday']           = '';
		$userinfo['radio_38']       = '';
		$userinfo['radio_39']       = '';
		$userinfo['name']           = '';
		$userinfo['radio_33']       = '';
		$userinfo['radio_34']       = '';
		$userinfo['radio_35']       = '';
		$userinfo['radio_36']       = '';
		$userinfo['radio_30']       = '';
		$userinfo['radio_31']       = '';
		$userinfo['radio_32']       = '';
		$userinfo['radio_2']        = '';
		$userinfo['intstick5z']     = '';
		$userinfo['dsearch']        = '';
		$userinfo['radio_3']        = '';
		$userinfo['radio_1']        = '';
		$userinfo['dream_name']     = '';
		$userinfo['MtDay']          = '';
		$userinfo['radio_28']       = '';
		$userinfo['radio_29']       = '';
		$userinfo['radio_26']       = '';
		$userinfo['radio_27']       = '';
		$userinfo['radio_24']       = '';
		$userinfo['radio_7']        = '';
		$userinfo['radio_25']       = '';
		$userinfo['radio_6']        = '';
		$userinfo['radio_22']       = '';
		$userinfo['radio_5']        = '';
		$userinfo['radio_23']       = '';
		$userinfo['radio_4']        = '';
		$userinfo['cmonth']         = '';
		$userinfo['radio_20']       = '';
		$userinfo['name1']          = '';
		$userinfo['radio_21']       = '';
		$userinfo['serial']         = '';
		$userinfo['radio_9']        = '';
		$userinfo['radio_8']        = '';
		
		// 나의 사주 정보 셋팅
		$userinfo['user_name']      = '한영수';
		$userinfo['sex']            = '남';
		$userinfo['solunar']        = 'lunar';
		$userinfo['my_solnuar']     = $userinfo['solunar'];
		$userinfo['request_year']   = '1988';
		$userinfo['request_month']  = '05';
		$userinfo['request_day']    = '05';
		
		$userinfo['yyyy']           = date('Y',time());
		$userinfo['solunar']        = 'solar';
		$userinfo['my_solnuar']     = $userinfo['solunar'];
		$userinfo['request_hour']   = '0';
		$userinfo['youn']           = '0';
		$userinfo['setDate']        = date("Y-m-d",time());	// 오늘날짜

		// 운세 결과 키값(db_express) 데이터 가져오기
		$star_unse = $this->model->get_db_express($userinfo);
		echo "<pre>";
		print_r($star_unse);
		echo "</pre>";
	}
}
/* End of file starunse.php */
/* Location: ./application/controllers/star/starunse.php */